class Watcher

   def tweet(tname, text)
      offers = []
      new_loc = text.sub!(/(^| )L:(.+?)(:|$)/, '')
      text.sub!(/(^| )\+(\d+)m( |$)/){ timeframe = $2.to_i.minutes }
      text.gsub!(/(^| )\+(.+?)( |$)/){ offers << $2 }
      wish = text.sub(/^(i )?(wish|want|pray|summon|invoke|seek)( for)?:?/i, '')
      if wish or timeframe or new_loc
         dude = Agent.find_or_create_by_tname(tname)
         new_loc   and dude.new_loc_on = Time.now and dude.save!
         wish      and dude.wish = wish and dude.wished_at = Time.now and dude.save!
         timeframe and dude.update_attributes!(
               :available_at => Time.now,
               :busy_at      => Time.now + timeframe,
               :offers       => offers
         )
      end
   end
   
   def tweet
      user_id = mysql_query("select id from user where tname = '$blah'")
      

   def assign(author, agent, target, instructions)
      author  = Agent.find_or_create_by_tname(author)
      agent   = Agent.find_or_create_by_tname(agent)
      target = Agent.find_or_create_by_tname(target)

      throw "that author cannot give assignments" if author.bad?
      throw "that agent is not actually available" unless agent.available?
      
      # calculate end_time of mission and update _to_'s availability
      earliest = [agent.busy_at, 30.minutes.from_now]
      earliest << target.busy_at if target.available?
      agent.available_at = earliest.min

      # put _to_'s assignment on the books
      p = Project.find_or_create_by_agent_and_target_and_wish(author, target, target.wish)
      p.assignments.create(
         :agent => agent,
         :instructions => instructions
      )
      
      # direct msg _to_ to give him his assignment
      twitter "d #{agent.tname} #{author.level} #{instructions}"
   end
   
   def review(reviewer, score, text)
      reviewer.latest_assignment.update_attributes!(
         :experience => score,
         :experience_desc => text
      )
      project = reviewer.latest_assignment.project
      project.update_attribute(:experince, score) if reviewer == project.target
   end
   
end


class Reporter
   def all_cities
      # for each city, all availabilities and all wishes
   end
   
   def high_scorers
   end
   
   def all_teams
   end
   
   def all_wishes
      # for each wish, the number of availabilities in that city
   end
   
   def all_available_agents
      # for availability, the numbers of availabilities and wishes in that city
   end
end


class TextFmt
end
